/*
 * Course:    CS 590 Web Services
 * Semseter:  Spring 2009
 * Professor: Sedlemeyer
 * Project:   CHEAT (Code Help Educational Assignment Tool)
 * Due Date:  May 1, 2009
 * Team:      Sarcasm
 *            (Baker, Jason; Mitchell, Robin; Shie, Keith)
 */

package cheat.entities;

import cheat.entities.keys.AssignmentAclPK;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * Assignment Access Control List
 *
 * @author Keith Shie
 * Date:    Mar 31, 2009
 */
@Entity
@Table(name = "asgn_acl")
@IdClass(AssignmentAclPK.class)
@NamedQueries({@NamedQuery(name = "AssignmentAcl.findAll", query = "SELECT a FROM AssignmentAcl a"),
        @NamedQuery(name = "AssignmentAcl.findByUuid", query = "SELECT a FROM AssignmentAcl a WHERE a.uuid = :uuid"),
        @NamedQuery(name = "AssignmentAcl.findByAcl", query = "SELECT a FROM AssignmentAcl a WHERE a.acl = :acl")})
public class AssignmentAcl implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Basic(optional = false)
  @Column(name = "uuid", nullable = false)
  private int uuid;
  @Id
  @Basic(optional = false)
  @Column(name = "acl", nullable = false, length = 20)
  private String acl;
  @JoinColumns({@JoinColumn(name = "uuid", referencedColumnName = "uuid", nullable = false, insertable = false, updatable =
          false)})
  @ManyToOne(optional = false)
  private AssignmentProperty assignmentProperty;

  public AssignmentAcl() {
  }

  public AssignmentAcl(int uuid, String acl) {
    this.uuid = uuid;
    this.acl = acl;
  }


  public String getAcl() {
    return acl;
  }


  public void setAcl( String acl ) {
    this.acl = acl;
  }


  public int getUuid() {
    return uuid;
  }


  public void setUuid( int uuid ) {
    this.uuid = uuid;
  }

  public AssignmentProperty getAssignmentProperty() {
    return assignmentProperty;
  }

  public void setAssignmentProperty(AssignmentProperty assignmentProperty) {
    this.assignmentProperty = assignmentProperty;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (int) uuid;
    hash += (acl != null ? acl.hashCode() : 0);
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof AssignmentAcl)) {
      return false;
    }
    AssignmentAcl other = (AssignmentAcl) object;
    if (this.uuid != other.uuid) {
      return false;
    }
    if ((this.acl == null && other.acl != null) || (this.acl != null && !this.acl.equals(other.acl))) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "cheat.entities.AssignmentAcl[uuid=" + uuid + ", acl=" + acl + "]";
  }

}
